<?php 
global $options;
foreach ($options as $value) {
    if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }
}
$dateformat = get_option('date_format');
$timeformat = get_option('time_format');
$layout = get_post_meta($post->ID, 'template', true);
get_header(); ?>


  <div id="content">
    <div class="wrap">    
      <?php wp_reset_query(); 
      if (have_posts()) : while (have_posts()) : the_post(); ?>

      <?php if ($layout != 'full') { ?>
      <div class="column column-narrow">
      
      	<?php 
      	$currCat = get_the_category();
      	$current = $currCat[0]->name;
      	$parent = get_cat_name($currCat[0]->category_parent);
      	
    	echo "<p class='heading'>".$parent."</p>";
		
		list_cat_posts_all();
		
		?>
      
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar: Posts (Left)') ) : ?>&nbsp;<?php endif; ?>
      
      </div><!-- end .column-narrow -->
      <?php } ?>
      <?php
	  	$project_slug = $_GET['project'];
	
		$args = array(
			'name' => $project_slug	   
		);
	
		$individual_query = new WP_Query( $args );
		$title = $individual_query->posts[0]->post_title;
	  ?>
      
      <div class="column <?php if ($layout == 'double') {echo"column-double column-last ";} if ($layout == 'full') {echo"column-full column-last ";} ?>column-content column-double">
	  	<div id="crumbs">
			<!--?php the_breadcrumb(); ?-->
			<?php
				$args = array(
					'prefix' => '<p>',
					'suffix' => '<strong>: '.$title.'</strong></p>',
					'title' => __( '', 'breadcrumbs-plus' ),
					'home' => __( 'Home', 'breadcrumbs-plus' ),
					'sep' => '»',
					'front_page' => false,
					'bold' => true,
					'show_blog' => false,
					'echo' => true,
					'singular_post_taxonomy' => 'category',
				);
				breadcrumbs_plus( $args );
			?>
		</div>
    <?php
		if ( $individual_query->have_posts()) : while ( $individual_query->have_posts()) : $individual_query->the_post();
	?>
    
	  	<h1><?php the_title(); ?></h1>
        
        <?php
		
		$the_content = return_the_content('');
		//project details from magic fields
       	$project_info= get_group('Project Details'); // use the Custom Group name
		/*print_r( $project_info );*/
        if ( !is_null( $project_info ) ) {
			foreach( $project_info as $detail ){
				//assign each field a variable name
				$start_yr = $detail['project_detail_start_year'][1];
				$end_yr = $detail['project_detail_end_year'][1];
				if ( $start_yr !== $end_yr ) { $years = $start_yr.'-'.$end_yr; } else { $years = $end_yr; }
				$agencies = $detail['project_detail_funding_agency'];
				$agency_string='';
				if ( $agencies ) {
					foreach( $agencies as $agency ) {
						$agency_string .= $agency.",&nbsp;";
					}
				}
				$agency_string = rtrim( $agency_string, ',&nbsp;' );
				$princ_invest = $detail['project_detail_principal_investigator'][1];
				$pi_post = get_post( $princ_invest ); 
				$pi_name = $pi_post->post_title;
				$pi_permalink = get_permalink( $princ_invest );
				if ( ! $pi_name || stristr( $pi_name , 'other' ) ) {
					$pi_name = $detail['project_detail_if_other_pi'][1];
					$pi_permalink = '';
					$p_invest_string = $pi_name;
				}
				if ($princ_invest) {
					if ( $princ_invest != 'Other, enter name below' ) {
						$p_invest_string = "<a title='".$pi_name."' href='".$pi_permalink."'>".$pi_name."</a>";
					}
				}
				$proj_link = $detail['project_detail_project_link'][1];
				if ($proj_link) {
					$proj_link_a = parse_url($proj_link);
					if(in_array("http", $proj_link_a) || in_array("ftp", $proj_link_a)) {
					    $proj_link = $proj_link;
					}
					else {
						$proj_link = "http://".$proj_link; 
					}
					$proj_link_string = "<a title='Link to project's Web site' href='".$proj_link."'>".$proj_link."</a>";
				}
				
				//if ( $pi_permalink ) { $p_invest_string = "<a title='".$pi_name."' href='".$pi_permalink."'>".$pi_name."</a>"; } else { $p_invest_string = $pi_name; }

			//end foreach permclassinfo as perminfo
			}  
		//end if not null permclassinfo
		}
		
		echo $the_content;
		
		echo "<dl class='tablelike'>";
			echo "<dt>Years</dt><dd>".$years."</dd>";
			if ( $p_invest_string ) {
				echo "<dt>Principal Investigator</dt><dd>".$p_invest_string."</dd>";
			}
			if ( $agency_string ) {
				echo "<dt>Agencies</dt><dd>".$agency_string."</dd>";
			}
			if ( $proj_link ) {
				echo "<dt>Project Link</dt><dd>".$proj_link_string."</dd>";
			}
		echo "</dl>";

		?>
        
        <?php 
			if ( is_single( 'hours' ) ) {
				if( function_exists( 'class_calendar' ) ) {
					class_calendar(); 
				}
			}
		?>
        
        <?php wp_link_pages(array('before' => '<p class="pages"><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
        <?php the_tags( '<p class="tags"><strong>Tags:</strong> ', ', ', '</p>'); ?>
        
        <?php 
		$faux_cat_post_id = get( 'details_project_category' );
		$faux_cat_link = get_permalink( $faux_cat_post_id );
		$faux_cat_post = get_post( $faux_cat_post_id ); 
		$faux_cat = $faux_cat_post->post_title;
		?>
        <p class="postmetadata"> Updated <span class="datetime"><?php the_time("$dateformat"); ?></span> &nbsp;&nbsp; See all projects under <span class="category"><a href="<?php echo $faux_cat_link; ?>"><?php echo $faux_cat; ?></a></span></p>
        <?php comments_template(); ?>
      
      </div><!-- end .column-content -->

      <?php if ($layout != 'double' && $layout != 'full') { ?><div class="column column-narrow column-last">
      
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar: Posts (Right)') ) : ?>&nbsp;<?php endif; ?>
      
      </div><!-- end .column-narrow -->
      <?php } ?>
	  <?php	endwhile; endif; ?>
<?php endwhile; endif; ?>

      <div class="clear">&nbsp;</div>

    </div><!-- end .wrap -->
  </div><!-- end #content -->

<?php get_footer(); ?>
